package com.songshuai.pangu.api.backcontroller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.songshuai.webapi.baseapi.dto.feign.response.sopmanage.CustomerListResDto;
import com.songshuai.webapi.baseapi.pojo.QueryPageRes;
import com.songshuai.webapi.baseapi.pojo.QueryRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author:wanglei
 * @Date: 2019/3/28
 */
@Slf4j
@Api("推送客户列表")
@RestController
@RequestMapping("api/back/customer/")
public class CustomerController {

    @ApiOperation(value = "根据userId查询维护的客户列表")
    @GetMapping("customerList")
    public QueryRes<QueryPageRes<List<CustomerListResDto>>> getCustomerListByUserId(@RequestParam("userId") String userId,
                                                                                         @RequestParam("bindStatus") Integer bindStatus,
                                                                                         @RequestParam("customerStatus") Integer customerStatus,
                                                                                         @RequestParam("pageIndex") Integer pageIndex,
                                                                                         @RequestParam("pageSize") Integer pageSize){
        List<CustomerListResDto> resList = new ArrayList<>();
        String customers = "[{\"customerName\":\"18100092532\",\"customerId\":\"190216004964\",\"customerStatus\":\"销售新线索\",\"bindStatus\":\"已绑定\",\"telephone\":\"18100092532\"}," +
                "{\"customerName\":\"汪礼贵\",\"customerId\":\"190320006750\",\"customerStatus\":\"销售新线索\",\"bindStatus\":\"已绑定\",\"telephone\":\"15801907192\"}," +
                "{\"customerName\":\"丽水\",\"customerId\":\"190311005665\",\"customerStatus\":\"已邀约客户\",\"bindStatus\":\"未绑定\",\"telephone\":\"15207555555\"}]";
        JSONArray customerJSONArray = JSONArray.parseArray(customers);
        customerJSONArray.stream().forEach(customerJson ->{
            JSONObject json = (JSONObject) customerJson;
            CustomerListResDto customer = JSONObject.parseObject(json.toString(), CustomerListResDto.class);
            resList.add(customer);
        });
        return QueryPageRes.setQueryResData(resList, 10L);
    }
}
